home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / ACCESS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  593 b   |  26 lines

  1. /* access.c, from page 350 of Turbo C Bible */
  2. #include<stdio.h>
  3. #include<io.h>
  4. char filename [] = "c:\\config.sys";
  5. main ()
  6. {
  7.    FILE *infile;
  8.    char buffer [80];
  9.                /* Check if the file exists. Note that
  10.                     we need two '\' */
  11.    if (access(filename, 4) == -1)
  12.    {
  13.         perror ("access failed");
  14.         exit (1);
  15.    }
  16.    if ((infile = fopen (filename, "r")) == NULL)
  17.    {
  18.         perror ("fopen failed");
  19.         exit (1);
  20.    }
  21.    printf ("Contents of %s\n", filename);
  22.    while (fgets (buffer, 80, infile) != NULL)
  23.    {
  24.         printf (buffer);
  25.    }
  26. }